package Leetcode250618.array;

import java.util.HashMap;
import java.util.Map;

/**
 * @description:  两数之和  [2,7,11,15]
 * @author: ChenYawei
 * @date: 2025/6/18  16:23
 */
public class TwoSum {

    public int[] twoSum(int[] nums, int target) {
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            int num = nums[i];
            if (map.containsKey(num)) {
                return new int[]{map.get(num), i};
            }
            int tmp = target - num;
            map.put(tmp, i);
        }
        return null;
    }

}
